
(function(angular){
  
	//angular module
    var myApp = angular.module('myApp', ['angularTreeview']);

    //test controller
    myApp.controller('GetCategories', function($scope, $http){
	
	$scope.url = 'Services/Categories/getcategories.php';

	try
	{
		$http({
			method: 'POST',
			url: $scope.url,
			headers: {'Content-Type': 'application/x-www-form-urlencoded'}
		}).
		success(function(data, status) 
		{
			$scope.status = status;
			$scope.data = data;
			$scope.result = data; // Show result from server in our <pre></pre> element
			
			if($scope.data != null)
			{
				$scope.roleList1 = [{ "roleName" : 'Categories', "roleId" : "role1", "children" : []}];
					
				for (index = 0; index < $scope.data.length; ++index) 
				{
					$scope.roleList1[0].children.push({ "roleName" : $scope.data[index], "roleId" : "role11", "children" : [] });
				}
				
				//roleList1 to treeview
				$scope.roleList = $scope.roleList1;
			}
		}).
		error(function(data, status) {
			$scope.data = data || "Request failed";
			$scope.status = status;			
		});
	}
	catch(err) 
	{
		alert("GetCategories : " + err.message);
	}		

	
  
  });
  
})(angular);

/*
    angular.treeview.js
*/
(function(l){l.module("angularTreeview",[]).directive("treeModel",function($compile){return{restrict:"A",link:function(a,g,c){var e=c.treeModel,h=c.nodeLabel||"label",d=c.nodeChildren||"children",k='<ul><li data-ng-repeat="node in '+e+'"><i class="collapsed" data-ng-show="node.'+d+'.length && node.collapsed" data-ng-click="selectNodeHead(node, $event)"></i><i class="expanded" data-ng-show="node.'+d+'.length && !node.collapsed" data-ng-click="selectNodeHead(node, $event)"></i><i class="normal" data-ng-hide="node.'+
d+'.length"></i> <span data-ng-class="node.selected" data-ng-click="selectNodeLabel(node, $event)">{{node.'+h+'}}</span><div data-ng-hide="node.collapsed" data-tree-model="node.'+d+'" data-node-id='+(c.nodeId||"id")+" data-node-label="+h+" data-node-children="+d+"></div></li></ul>";e&&e.length&&(c.angularTreeview?(a.$watch(e,function(m,b){g.empty().html($compile(k)(a))},!1),a.selectNodeHead=a.selectNodeHead||function(a,b){b.stopPropagation&&b.stopPropagation();b.preventDefault&&b.preventDefault();b.cancelBubble=
!0;b.returnValue=!1;a.collapsed=!a.collapsed},a.selectNodeLabel=a.selectNodeLabel||function(c,b){b.stopPropagation&&b.stopPropagation();b.preventDefault&&b.preventDefault();b.cancelBubble=!0;b.returnValue=!1;a.currentNode&&a.currentNode.selected&&(a.currentNode.selected=void 0);c.selected="selected";a.currentNode=c}):g.html($compile(k)(a)))}}})})(angular);